home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 335_03 / as8048.y < prev    next >
Text File  |  1990-12-02  |  40KB  |  1,757 lines

  1. %{
  2.  
  3. /*
  4. HEADER:     ;
  5. TITLE:         Frankenstein Cross Assemblers;
  6. VERSION:     2.0;
  7. DESCRIPTION: "    Reconfigurable Cross-assembler producing Intel (TM)
  8.         Hex format object records.  ";
  9. KEYWORDS:     cross-assemblers, 1805, 2650, 6301, 6502, 6805, 6809, 
  10.         6811, tms7000, 8048, 8051, 8096, z8, z80;
  11. SYSTEM:     UNIX, MS-Dos ;
  12. FILENAME:     as8048.y;
  13. WARNINGS:     "This software is in the public domain.  
  14.         Any prior copyright claims are relinquished.  
  15.  
  16.         This software is distributed with no warranty whatever.  
  17.         The author takes no responsibility for the consequences 
  18.         of its use.
  19.  
  20.         Yacc (or Bison) required to compile."  ;
  21. SEE-ALSO:     as8048.doc,frasmain.c;    
  22. AUTHORS:     Mark Zenier;
  23. COMPILERS:     Microport Sys V/AT, ATT Yacc, Turbo C V1.5, Bison (CUG disk 285)
  24.         (previous versions Xenix, Unisoft 68000 Version 7, Sun 3);
  25. */
  26. /* 8048  et al  instruction generation file */
  27. /* November 17, 1990 */
  28.  
  29. /*
  30.     description    frame work parser description for framework cross
  31.             assemblers
  32.     history        February 2, 1988
  33.             September 11, 1990 - merge table definition
  34.             September 12, 1990 - short file names
  35.             September 14, 1990 - short variable names
  36.             September 17, 1990 - use yylex as external
  37. */
  38. #include <stdio.h>
  39. #include "frasmdat.h"
  40. #include "fragcon.h"
  41.  
  42. #define yylex lexintercept
  43.  
  44. /* 0000.0000.0000.xxxx  interrupt selections */
  45. #define    ISELMASK    0xf
  46. #define    ISELI        0x1
  47. #define    ISELTCNTI    0x2
  48. #define    ISELDMA        0x4
  49. #define    ISELFLAGS    0x8
  50. /* 0000.0000.0000.xxxx  accum-flag selections */
  51. #define    AFSELMASK    0xf
  52. #define    AFSELA        0x1
  53. #define    AFSELC        0x2
  54. #define    AFSELF0        0x4
  55. #define    AFSELF1        0x8
  56. /* 0000.0000.xxxx.0000  low port selections */
  57. #define    PSELMASK    0xf0
  58. #define    PSELBUS        0x10
  59. #define    PSELP1        0x20
  60. #define    PSELP2        0x40
  61. #define    PSELDBB        0x80
  62. /* 0000.00xx.xxxx.0000  misc register selections */
  63. #define    MSELMASK    0x3f0
  64. #define    MSELPSW        0x10
  65. #define    MSELT        0x20
  66. #define    MSELCNT        0x40
  67. #define    MSELTCNT    0x80
  68. #define    MSELCLK        0x100
  69. #define    MSELSTS        0x200
  70. /* 0000.xx00.0000.0000  ram size */
  71. #define    RAMSIZEMASK    0xc00
  72. #define    RAMSIZE64    0x400
  73. #define    RAMSIZE128    0x800
  74. #define    RAMSIZE256    0xc00
  75. /* xxx0.0000.0000.0000  instruction set variations */
  76. #define    INSTIDL        0x8000
  77. #define    INSTNOT41    0x4000
  78. #define    INST41        0x2000
  79. #define    CPU8048        INSTNOT41|RAMSIZE64
  80. #define    CPU8049        INSTNOT41|RAMSIZE128
  81. #define    CPU8050        INSTNOT41|RAMSIZE256
  82. #define    CPU80C48    INSTNOT41|INSTIDL|RAMSIZE64
  83. #define    CPU80C49    INSTNOT41|INSTIDL|RAMSIZE128
  84. #define    CPU80C50    INSTNOT41|INSTIDL|RAMSIZE256
  85. #define    CPU8041        INST41|RAMSIZE64
  86. #define    CPU8042        INST41|RAMSIZE128
  87. #define ST_AF 0x1
  88. #define ST_REG 0x2
  89. #define ST_EXPR 0x4
  90. #define ST_AR 0x8
  91. #define ST_AINDIRR 0x10
  92. #define ST_AIMMED 0x20
  93. #define ST_INDIRA 0x40
  94. #define ST_INDIRR 0x80
  95. #define ST_REGEXP 0x100
  96. #define ST_PA2 0x200
  97. #define ST_PA4 0x400
  98. #define ST_P2A 0x800
  99. #define ST_P4A 0x1000
  100. #define ST_P2IMMED 0x2000
  101. #define ST_INH 0x1
  102. #define ST_INT 0x2
  103. #define ST_RSELC 0x4
  104. #define ST_MSELC 0x8
  105. #define ST_MREG 0x10
  106. #define ST_MAR 0x1
  107. #define ST_MAINDIRA 0x2
  108. #define ST_MAINDIRR 0x4
  109. #define ST_MAIMMED 0x8
  110. #define ST_MAMR 0x10
  111. #define ST_MMRA 0x20
  112. #define ST_MRA 0x40
  113. #define ST_MRIMMED 0x80
  114. #define ST_MINDIRRA 0x100
  115. #define ST_MINDIRRIM 0x200
  116.     
  117.     static char    genbdef[] = "[1=];";
  118.     static char    genwdef[] = "[1=]y"; /* x for normal, y for byte rev */
  119.     char ignosyn[] = "[Xinvalid syntax for instruction";
  120.     char ignosel[] = "[Xinvalid operands/illegal instruction for cpu";
  121.     int    cpuselect = CPU80C50;
  122.  
  123.     long    labelloc;
  124.     static int satsub;
  125.     int    ifstkpt = 0;
  126.     int    fraifskip = FALSE;
  127.  
  128.     struct symel * endsymbol = SYMNULL;
  129.  
  130. %}
  131. %union {
  132.     int    intv;
  133.     long     longv;
  134.     char    *strng;
  135.     struct symel *symb;
  136. }
  137.  
  138. %token <intv> RSELC
  139. %token <intv> MSELC
  140. %token <intv> INT
  141. %token <intv> AF
  142. %token <intv> REG
  143. %token <intv> P02
  144. %token <intv> P47
  145. %token <intv> MREG
  146. %token <intv> KOC_BDEF
  147. %token <intv> KOC_ELSE
  148. %token <intv> KOC_END
  149. %token <intv> KOC_ENDI
  150. %token <intv> KOC_EQU
  151. %token <intv> KOC_IF
  152. %token <intv> KOC_INCLUDE
  153. %token <intv> KOC_ORG
  154. %token <intv> KOC_RESM
  155. %token <intv> KOC_SDEF
  156. %token <intv> KOC_SET
  157. %token <intv> KOC_WDEF
  158. %token <intv> KOC_CHSET
  159. %token <intv> KOC_CHDEF
  160. %token <intv> KOC_CHUSE
  161. %token <intv> KOC_CPU
  162. %token <intv> KOC_REG
  163. %token <intv> KOC_opcode
  164. %token <intv> KOC_misc
  165. %token <intv> KOC_mov
  166.  
  167. %token <longv> CONSTANT
  168. %token EOL
  169. %token KEOP_AND
  170. %token KEOP_DEFINED
  171. %token KEOP_EQ
  172. %token KEOP_GE
  173. %token KEOP_GT
  174. %token KEOP_HIGH
  175. %token KEOP_LE
  176. %token KEOP_LOW
  177. %token KEOP_LT
  178. %token KEOP_MOD
  179. %token KEOP_MUN
  180. %token KEOP_NE
  181. %token KEOP_NOT
  182. %token KEOP_OR
  183. %token KEOP_SHL
  184. %token KEOP_SHR
  185. %token KEOP_XOR
  186. %token KEOP_locctr
  187. %token <symb> LABEL
  188. %token <strng> STRING
  189. %token <symb> SYMBOL
  190.  
  191. %token KTK_invalid
  192.  
  193. %right    KEOP_HIGH KEOP_LOW
  194. %left    KEOP_OR KEOP_XOR
  195. %left    KEOP_AND
  196. %right    KEOP_NOT
  197. %nonassoc    KEOP_GT KEOP_GE KEOP_LE KEOP_LT KEOP_NE KEOP_EQ
  198. %left    '+' '-'
  199. %left    '*' '/' KEOP_MOD KEOP_SHL KEOP_SHR
  200. %right    KEOP_MUN
  201.  
  202.  
  203. %type <intv> expr exprlist stringlist
  204.  
  205. %start file
  206.  
  207. %%
  208.  
  209. file    :    file allline
  210.     |    allline
  211.     ;
  212.  
  213. allline    :     line EOL
  214.             {
  215.                 clrexpr();
  216.             }
  217.     |    EOL
  218.     |    error EOL
  219.             {
  220.                 clrexpr();
  221.                 yyerrok;
  222.             }
  223.     ;
  224.  
  225. line    :    LABEL KOC_END 
  226.             {
  227.                 endsymbol = $1;
  228.                 nextreadact = Nra_end;
  229.             }
  230.     |          KOC_END 
  231.             {
  232.                 nextreadact = Nra_end;
  233.             }
  234.     |    KOC_INCLUDE STRING
  235.             {
  236.         if(nextfstk >= FILESTKDPTH)
  237.         {
  238.             fraerror("include file nesting limit exceeded");
  239.         }
  240.         else
  241.         {
  242.             infilestk[nextfstk].fnm = savestring($2,strlen($2));
  243.             if( (infilestk[nextfstk].fpt = fopen($2,"r"))
  244.                 ==(FILE *)NULL )
  245.             {
  246.                 fraerror("cannot open include file");
  247.             }
  248.             else
  249.             {
  250.                 nextreadact = Nra_new;
  251.             }
  252.         }
  253.             }
  254.     |    LABEL KOC_EQU expr 
  255.             {
  256.                 if($1 -> seg == SSG_UNDEF)
  257.                 {
  258.                     pevalexpr(0, $3);
  259.                     if(evalr[0].seg == SSG_ABS)
  260.                     {
  261.                         $1 -> seg = SSG_EQU;
  262.                         $1 -> value = evalr[0].value;
  263.                         prtequvalue("C: 0x%lx\n",
  264.                             evalr[0].value);
  265.                     }
  266.                     else
  267.                     {
  268.                         fraerror(
  269.                     "noncomputable expression for EQU");
  270.                     }
  271.                 }
  272.                 else
  273.                 {
  274.                     fraerror(
  275.                 "cannot change symbol value with EQU");
  276.                 }
  277.             }
  278.     |    LABEL KOC_SET expr 
  279.             {
  280.                 if($1 -> seg == SSG_UNDEF
  281.                    || $1 -> seg == SSG_SET)
  282.                 {
  283.                     pevalexpr(0, $3);
  284.                     if(evalr[0].seg == SSG_ABS)
  285.                     {
  286.                         $1 -> seg = SSG_SET;
  287.                         $1 -> value = evalr[0].value;
  288.                         prtequvalue("C: 0x%lx\n",
  289.                             evalr[0].value);
  290.                     }
  291.                     else
  292.                     {
  293.                         fraerror(
  294.                     "noncomputable expression for SET");
  295.                     }
  296.                 }
  297.                 else
  298.                 {
  299.                     fraerror(
  300.                 "cannot change symbol value with SET");
  301.                 }
  302.             }
  303.     |    KOC_IF expr 
  304.             {
  305.         if((++ifstkpt) < IFSTKDEPTH)
  306.         {
  307.             pevalexpr(0, $2);
  308.             if(evalr[0].seg == SSG_ABS)
  309.             {
  310.                 if(evalr[0].value != 0)
  311.                 {
  312.                     elseifstk[ifstkpt] = If_Skip;
  313.                     endifstk[ifstkpt] = If_Active;
  314.                 }
  315.                 else
  316.                 {
  317.                     fraifskip = TRUE;
  318.                     elseifstk[ifstkpt] = If_Active;
  319.                     endifstk[ifstkpt] = If_Active;
  320.                 }
  321.             }
  322.             else
  323.             {
  324.                 fraifskip = TRUE;
  325.                 elseifstk[ifstkpt] = If_Active;
  326.                 endifstk[ifstkpt] = If_Active;
  327.             }
  328.         }
  329.         else
  330.         {
  331.             fraerror("IF stack overflow");
  332.         }
  333.             }
  334.                         
  335.     |    KOC_IF 
  336.             {
  337.         if(fraifskip) 
  338.         {
  339.             if((++ifstkpt) < IFSTKDEPTH)
  340.             {
  341.                     elseifstk[ifstkpt] = If_Skip;
  342.                     endifstk[ifstkpt] = If_Skip;
  343.             }
  344.             else
  345.             {
  346.                 fraerror("IF stack overflow");
  347.             }
  348.         }
  349.         else
  350.         {
  351.             yyerror("syntax error");
  352.             YYERROR;
  353.         }
  354.                 }
  355.                         
  356.     |    KOC_ELSE 
  357.             {
  358.                 switch(elseifstk[ifstkpt])
  359.                 {
  360.                 case If_Active:
  361.                     fraifskip = FALSE;
  362.                     break;
  363.                 
  364.                 case If_Skip:
  365.                     fraifskip = TRUE;
  366.                     break;
  367.                 
  368.                 case If_Err:
  369.                     fraerror("ELSE with no matching if");
  370.                     break;
  371.                 }
  372.             }
  373.  
  374.     |    KOC_ENDI 
  375.             {
  376.                 switch(endifstk[ifstkpt])
  377.                 {
  378.                 case If_Active:
  379.                     fraifskip = FALSE;
  380.                     ifstkpt--;
  381.                     break;
  382.                 
  383.                 case If_Skip:
  384.                     fraifskip = TRUE;
  385.                     ifstkpt--;
  386.                     break;
  387.                 
  388.                 case If_Err:
  389.                     fraerror("ENDI with no matching if");
  390.                     break;
  391.                 }
  392.             }
  393.     |    LABEL KOC_ORG expr 
  394.             {
  395.                 pevalexpr(0, $3);
  396.                 if(evalr[0